/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：实现各个级别的日志输出
* CreateTime：2020-04-05 19:47:24
* Version：1.0
* Modify Recorder：
*************************************************/

using System.Diagnostics;

namespace TinyToolKit
{
    /// <summary>
    /// 日志输出工具类
    /// </summary>
    public static partial class TLogTool 
    {
        private static ILogTemplate _template;

        private static ILogTemplate LogTemplate
        {
            get => _template ?? (_template = new DefaultLogTemplate());
            set => _template = value;
        }

        /// <summary>
        /// 设置输出日志的模板
        /// </summary>
        /// <param name="logTemplate">日志模板类型</param>
        public static void SetLogTemplate(ILogTemplate logTemplate)
        {
            LogTemplate = logTemplate;
        }

        #region DEBUG 调试级别日志
        [Conditional("ENABLE_DEBUG")]
        public static void Debug(string msg)
        {
            LogTemplate?.Log(LogLevel.DEBUG, msg);
        }

        [Conditional("ENABLE_DEBUG")]
        public static void Debug(object obj)
        {
            LogTemplate?.Log(LogLevel.DEBUG, obj);
        }

        [Conditional("ENABLE_DEBUG")]
        public static void Debug(string format, object arg0)
        {
            LogTemplate?.Log(LogLevel.DEBUG, string.Format(format, arg0));
        }

        [Conditional("ENABLE_DEBUG")]
        public static void Debug(string format, object arg0,object arg1)
        {
            LogTemplate?.Log(LogLevel.DEBUG, string.Format(format, arg0,arg1));
        }

        [Conditional("ENABLE_DEBUG")]
        public static void Debug(string format, object arg0, object arg1,object arg2)
        {
            LogTemplate?.Log(LogLevel.DEBUG, string.Format(format, arg0, arg1 ,arg2));
        }

        //日志参数超过 3 个（≥4）时，将会生成可变参数数组，导致额外的内存分配。
        [Conditional("ENABLE_DEBUG")]
        public static void Debug(string format, params object[] args)
        {
            LogTemplate?.Log(LogLevel.DEBUG, string.Format(format, args));
        }
        #endregion

        #region INFO 信息级别日志
        [Conditional("ENABLE_INFO")]
        public static void Info(string msg)
        {
            LogTemplate?.Log(LogLevel.INFO, msg);
        }

        [Conditional("ENABLE_INFO")]
        public static void Info(object obj)
        {
            LogTemplate?.Log(LogLevel.INFO, obj);
        }

        [Conditional("ENABLE_INFO")]
        public static void Info(string format, object arg0)
        {
            LogTemplate?.Log(LogLevel.INFO, string.Format(format, arg0));
        }

        [Conditional("ENABLE_INFO")]
        public static void Info(string format, object arg0, object arg1)
        {
            LogTemplate?.Log(LogLevel.INFO, string.Format(format, arg0, arg1));
        }

        [Conditional("ENABLE_INFO")]
        public static void Info(string format, object arg0, object arg1, object arg2)
        {
            LogTemplate?.Log(LogLevel.INFO, string.Format(format, arg0, arg1, arg2));
        }

        //日志参数超过 3 个（≥4）时，将会生成可变参数数组，导致额外的内存分配。
        [Conditional("ENABLE_INFO")]
        public static void Info(string format, params object[] args)
        {
            LogTemplate?.Log(LogLevel.INFO, string.Format(format, args));
        }
        #endregion

        #region WARNING 警告级别日志
        [Conditional("ENABLE_WARNING")]
        public static void Warning(string msg)
        {
            LogTemplate?.Log(LogLevel.WARNING, msg);
        }

        [Conditional("ENABLE_WARNING")]
        public static void Warning(object obj)
        {
            LogTemplate?.Log(LogLevel.WARNING, obj);
        }

        [Conditional("ENABLE_WARNING")]
        public static void Warning(string format, object arg0)
        {
            LogTemplate?.Log(LogLevel.WARNING, string.Format(format, arg0));
        }

        [Conditional("ENABLE_WARNING")]
        public static void Warning(string format, object arg0, object arg1)
        {
            LogTemplate?.Log(LogLevel.WARNING, string.Format(format, arg0, arg1));
        }

        [Conditional("ENABLE_WARNING")]
        public static void Warning(string format, object arg0, object arg1, object arg2)
        {
            LogTemplate?.Log(LogLevel.WARNING, string.Format(format, arg0, arg1, arg2));
        }

        //日志参数超过 3 个（≥4）时，将会生成可变参数数组，导致额外的内存分配。
        [Conditional("ENABLE_WARNING")]
        public static void Warning(string format, params object[] args)
        {
            LogTemplate?.Log(LogLevel.WARNING, string.Format(format, args));
        }
        #endregion

        #region ERROR 错误级别日志
        [Conditional("ENABLE_ERROR")]
        public static void Error(string msg)
        {
            LogTemplate?.Log(LogLevel.ERROR, msg);
        }

        [Conditional("ENABLE_ERROR")]
        public static void Error(object obj)
        {
            LogTemplate?.Log(LogLevel.ERROR, obj);
        }

        [Conditional("ENABLE_ERROR")]
        public static void Error(string format, object arg0)
        {
            LogTemplate?.Log(LogLevel.ERROR, string.Format(format, arg0));
        }

        [Conditional("ENABLE_ERROR")]
        public static void Error(string format, object arg0, object arg1)
        {
            LogTemplate?.Log(LogLevel.ERROR, string.Format(format, arg0, arg1));
        }

        [Conditional("ENABLE_ERROR")]
        public static void Error(string format, object arg0, object arg1, object arg2)
        {
            LogTemplate?.Log(LogLevel.ERROR, string.Format(format, arg0, arg1, arg2));
        }

        //日志参数超过 3 个（≥4）时，将会生成可变参数数组，导致额外的内存分配。
        [Conditional("ENABLE_ERROR")]
        public static void Error(string format, params object[] args)
        {
            LogTemplate?.Log(LogLevel.ERROR, string.Format(format, args));
        }
        #endregion
    }
}

